home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v7n21.arc / FNGETKEY.BAS < prev    next >
BASIC Source File  |  1988-11-14  |  2KB  |  73 lines

  1. DEF FNGetKey$
  2.  
  3.     'Works like INKEY$, but also returns a repeat count for extended keys.
  4.  
  5.     STATIC GetKey$, ScanCode%, Mask%, Count%, InArray%(1), OutArray%(1)
  6.     REDIM InArray%(7), OutArray%(7)
  7.  
  8.     GetKey$ = INKEY$                    'get a keystroke
  9.     FNGetKey$ = GetKey$                 'set up default return value
  10.     IF LEN(GetKey$) <> 2 THEN EXIT DEF  'if null or normal key, exit
  11.  
  12.     ScanCode% = ASC(RIGHT$(GetKey$, 1)) 'isolate the key's scan code
  13.     Mask% = 8                           'assume it's an Alt-key for now
  14.     Count% = 1                          'assume no repeats for now
  15.  
  16.     SELECT CASE ScanCode%
  17.        CASE 94 TO 103           '<Ctrl-F1> through <Ctrl-F10>
  18.           Mask% = 4
  19.        CASE 115 TO 119          '<Ctrl-Left>, <Ctrl-Right>, <Ctrl-End>,
  20.           Mask% = 4             '<Ctrl-PgDn>, or <Ctrl-Home>
  21.        CASE 132
  22.           Mask% = 4             '<Ctrl-PgUp>
  23.        CASE ELSE
  24.     END SELECT
  25.  
  26.     'Wait for additional keystrokes until the user either releases the
  27.     '<Alt> or <Ctrl> key, or hits a different keystroke.
  28.  
  29. L1: InArray%(0) = &H200
  30.  
  31.     'Call the BIOS to get the status of the <ALT> and <CTRL> keys.
  32.     CALL INT86(&H16, VARPTR(InArray%(0)), VARPTR(OutArray%(0)))
  33.  
  34.     'Check the appropriate bit in the AL register.
  35.     IF (Mask% AND OutArray%(0)) = 0 GOTO Done
  36.  
  37.     'Call the BIOS to see if there is a keystroke waiting in the buffer.
  38.     InArray%(0) = &H100
  39.     CALL INT86(&H16, VARPTR(InArray%(0)), VARPTR(OutArray%(0)))
  40.  
  41.     'Check the Z flag in the FLAGS register to see if a keystroke is waiting.
  42.     IF (OutArray%(7) AND 64) = 64 GOTO L1
  43.  
  44.     'Examine AH register to see if keystroke matches the previous scan code.
  45.     IF PEEK(VARPTR(OutArray%(0)) + 1) <> ScanCode% GOTO Done
  46.  
  47.     'Remove the keystroke from the keyboard buffer and increment the count.
  48.     GetKey$ = INKEY$
  49.     Count% = Count% + 1
  50.     GOTO L1
  51.  
  52. Done: IF Count% <> 1 THEN FNGetKey$ = GetKey$ + CHR$(Count%)
  53.  
  54. END DEF
  55.  
  56. 'Test program for FNGetKey$
  57.  
  58. L2: Key$ = FNGetKey$
  59.     IF Key$ = "" GOTO L2
  60.  
  61.     SELECT CASE LEN(Key$)
  62.        CASE 1
  63.           PRINT Key$;
  64.        CASE 2
  65.           PRINT "Scan Code: "; ASC(MID$(Key$, 2));
  66.        CASE 3
  67.           PRINT "Scan Code: "; ASC(MID$(Key$, 2)),
  68.           PRINT "Count: "; ASC(RIGHT$(Key$, 1));
  69.     END SELECT
  70.     PRINT
  71.     GOTO L2
  72.  
  73.